package com.tdkj.action.backstage.risevalue;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import com.tdkj.action.BaseAction;
import com.tdkj.model.information.BeanExpert;
import com.tdkj.model.risevalue.BeanPlateSMS;
import com.tdkj.service.risevalue.IBeanPlateSMSService;


public class PlateSMSAction extends BaseAction {
    
	private IBeanPlateSMSService plateSMSService;
	
	private long id;
	
	private String name;
	
	private List<BeanPlateSMS> plates ;
	
	private BeanPlateSMS plate ;
	
	private String message;
	
	public String add() {
		plate = new BeanPlateSMS();
		plate.setName(name);
		
		plateSMSService.add(plate);
		this.setMessage("添加成功");
		return execute();
	}
	
	public String update() {
		plateSMSService.update(id, name);
		this.setMessage("保存成功");
		return execute();
	}

	public String del() {
		plateSMSService.delete(id);
		this.setMessage("删除成功");
		return "delete";
	}
	
	public String edit() {
		plate = plateSMSService.get(id);
		this.setMessage("获取成功");
		return "edit";
	}
	
	public String get() {
		plate = plateSMSService.get(id);
		this.setMessage("获取成功");
		return "get";
	}
	
	public String execute() {
		plates = plateSMSService.getAll();
		if(plates.size()==0){
			appendObj(10);
		}
		Criteria criteria = this.createCriteria(BeanPlateSMS.class);
		criteria.addOrder(Order.desc("name"));// 对状态进行排序
		this.queryByPage(criteria, "plateSMSAction", 10);
		return "success";
	}
	

	private void appendObj(int i) {
		// TODO Auto-generated method stub
		/*1.1新闻
		1..2西南原料行情报价
		1.2.1黑色金属
		1.2.2有色金属
		1.2.3非金属
		1.3期货、股票专家评论
		1.4行情指导
		1.5供求信息发布
		*/
		BeanPlateSMS bean=new BeanPlateSMS();
		bean.setName("新闻");
		plateSMSService.save(bean);
	    bean=new BeanPlateSMS();
		bean.setName("原料行情报价");
		plateSMSService.save(bean);
		bean=new BeanPlateSMS();
		bean.setName("黑色金属");
		plateSMSService.save(bean);
		bean=new BeanPlateSMS();
		bean.setName("有色金属");
		plateSMSService.save(bean);
		bean=new BeanPlateSMS();
		bean.setName("非金属");
		plateSMSService.save(bean);
		bean=new BeanPlateSMS();
		bean.setName("期货、股票专家评论");
		plateSMSService.save(bean);
		bean=new BeanPlateSMS();
		bean.setName("行情指导");
		plateSMSService.save(bean);
		bean=new BeanPlateSMS();
		bean.setName("供求信息");
		plateSMSService.save(bean);
	}

	@Resource
	public void setPlateSMSService(IBeanPlateSMSService plateSMSService) {
		this.plateSMSService = plateSMSService;
	}

	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the plates
	 */
	public List<BeanPlateSMS> getPlates() {
		return plates;
	}

	/**
	 * @param plates the plates to set
	 */
	public void setPlates(List<BeanPlateSMS> plates) {
		this.plates = plates;
	}

	/**
	 * @return the plate
	 */
	public BeanPlateSMS getPlate() {
		return plate;
	}

	/**
	 * @param plate the plate to set
	 */
	public void setPlate(BeanPlateSMS plate) {
		this.plate = plate;
	}

	
	
}
